// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   PositionHandle.java

package jones.gui;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.RectangularShape;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import javax.swing.event.MouseInputAdapter;

// Referenced classes of package jones.gui:
//            Position

public class PositionHandle extends JPanel
    implements Observer
{

    private Position position = null;
    private double offsetX = 0;
    private double offsetY = 0;
    private RectangularShape handleShape = null;

    public PositionHandle(Position position, RectangularShape handleShape)
    {
        this.position = position;
        offsetX = handleShape.getX() - position.getX();
        offsetY = handleShape.getY() - position.getY();
        this.handleShape = (RectangularShape)handleShape.clone();
        init();
    }

    private void init()
    {
        setOpaque(false);
        setForeground(Color.white);
        setBackground(Color.blue);
        setCursor(Cursor.getPredefinedCursor(0));
        setVisible(false);
        position.addObserver(((Observer) (this)));
        MouseInputAdapter mouseAdapter = ((MouseInputAdapter) (new MouseInputAdapter() {

            private Point start = null;

            public void mousePressed(MouseEvent e)
            {
                start.setLocation(e.getX(), e.getY());
            }

            public void mouseDragged(MouseEvent e)
            {
                position.setLocation((position.getX() + (double)e.getX()) - (double)start.x, (position.getY() + (double)e.getY()) - (double)start.y);
                start.setLocation(e.getX(), e.getY());
            }

            
            {
                start = new Point();
            }
        }
));
        addMouseMotionListener(((java.awt.event.MouseMotionListener) (mouseAdapter)));
        addMouseListener(((java.awt.event.MouseListener) (mouseAdapter)));
    }

    public void update(Observable obs, Object obj)
    {
        synchronized (handleShape)
        {
            handleShape.setFrame((int)(position.getX() + offsetX), (int)(position.getY() + offsetY), handleShape.getWidth(), handleShape.getHeight());
        }
        repaint();
    }

    public boolean contains(int x, int y)
    {
        return handleShape.contains(x, y);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        synchronized (handleShape)
        {
            Graphics2D g2d = (Graphics2D)g;
            g2d.setColor(getBackground());
            g2d.fill(((java.awt.Shape) (handleShape)));
            g2d.setColor(getForeground());
            g2d.draw(((java.awt.Shape) (handleShape)));
        }
    }

}
